package edu.whut.arraysTest;

import java.sql.SQLOutput;

public class BinaryFind {
    public static void main(String[] args) {
        int nums[] = {1,5,9,15,88,698};
        int key = 698;
        int re = binarySearch(nums, key);
        System.out.println(re);
    }

    private static int binarySearch(int[] nums, int key) {
        int low=0;
        int high=nums.length-1;
        int mid;
        while(low<=high){
            mid = (low+high)/2;
            if(key==nums[mid]) {
                return mid;
            }else if (key>nums[mid]){
                low = mid+1;
            }else {
                high = mid-1;
            }
        }
        return -1;
    }
}
